﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net.Mail;
using System.Net;
using System.Configuration;
using System.Threading;

namespace VehicleManagement.ControllersServices
{
    public class Utility
    {
        /// <summary>
        /// 发送邮件
        /// </summary>
        /// <param name="address"></param>
        /// <param name="subject"></param>
        /// <param name="text"></param>
        public static void SendEmail(string address, string subject, string text)
        {
            Thread t = new Thread
                (delegate()
                {
                    try
                    {
                        string serverAddress = ConfigurationManager.AppSettings["EmailAddress"];
                        string password = ConfigurationManager.AppSettings["EmailPassword"];
                        string host = ConfigurationManager.AppSettings["EmailHost"];

                        SmtpClient client = new SmtpClient();
                        client.Host = host;
                        client.UseDefaultCredentials = false;
                        client.Credentials = new NetworkCredential(serverAddress, password);
                        client.DeliveryMethod = SmtpDeliveryMethod.Network;

                        MailMessage message = new MailMessage(serverAddress, address);
                        message.Subject = subject;
                        message.Body = text;
                        message.BodyEncoding = System.Text.Encoding.UTF8;
                        message.IsBodyHtml = true;

                        client.Send(message);
                    }
                    catch (Exception)
                    {
                    }
                });
            t.Start();
        }
    }
}